from vec import Vec2
import math
import time
WIDTH = 500
HEIGHT = 500

PEN_COLOR = (0, 200, 0)
BACK_COLOR = (0, 0, 0)

lastTime = time.time()
deltaTime = 0

pt_a = Vec2(250, 100)
n_from = 50
n_to = 100
len = n_from
p = 0
p_spd = 1
def get_pt_by_len(pt_a, n):
    h = n / 2 * math.sqrt(3)
    pt_d = Vec2(pt_a.x, pt_a.y + h)
    pt_b = Vec2(pt_d.x - n / 2, pt_d.y)
    pt_c = Vec2(pt_d.x + n / 2, pt_d.y)

    return pt_a, pt_b, pt_c

def update():
    global deltaTime, lastTime, len, p, p_spd
    curTime = time.time()
    deltaTime = curTime - lastTime
    lastTime = curTime

    p += p_spd * deltaTime
    if p > 1.0:
        p = 1.0
        p_spd *= -1
    elif p < 0.0:
        p = 0.0
        p_spd *= -1

    len = n_from * (1 - p) + n_to * p

def draw():
    screen.fill(BACK_COLOR)
    a, b, c = get_pt_by_len(pt_a, len)
    screen.draw.line(a.raw_get(), b.raw_get(), PEN_COLOR)
    screen.draw.line(b.raw_get(), c.raw_get(), PEN_COLOR)
    screen.draw.line(c.raw_get(), a.raw_get(), PEN_COLOR)